package warmachineroster.presentation.policy;

import java.util.List;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.editpolicies.ComponentEditPolicy;
import org.eclipse.gef.requests.GroupRequest;

import warmachineroster.RosterElement;
import warmachineroster.UnitRosterElement;
import warmachineroster.presentation.command.UnitAttachmentRosterElementRemoveCommand;

public class UnitAttachmentRosterElementComponentEditPolicy extends ComponentEditPolicy {

	@Override
	protected Command createDeleteCommand(GroupRequest request) {
		CompoundCommand ccommand = new CompoundCommand();
		List<?> toBeRemoved = request.getEditParts(); 
		for(Object ep : toBeRemoved){
			EditPart editPart = (EditPart) ep;
			UnitAttachmentRosterElementRemoveCommand command = new UnitAttachmentRosterElementRemoveCommand();
			RosterElement  rosterElement = (RosterElement) editPart.getModel();
			command.setMotherUnit((UnitRosterElement) getHost().getParent().getModel());
			command.setRosterElement(rosterElement);
			ccommand.add(command);
		}
		return ccommand;
	}



}
